package com.example.wechatbot.config;

import com.github.jaemon.dinger.DingerSender;
import com.github.jaemon.dinger.core.entity.DingerRequest;
import com.github.jaemon.dinger.core.entity.enums.DingerType;
import com.github.jaemon.dinger.core.entity.enums.MessageSubType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class AppStartupNotifier implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    private DingerSender dingerSender;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        // 发送应用启动通知
        dingerSender.send(
                DingerType.WETALK,
                MessageSubType.TEXT,
                DingerRequest.request("企业微信机器人消息发送中间件已启动！")
        );

        // 发送Markdown格式的启动通知
        dingerSender.send(
                DingerType.WETALK,
                MessageSubType.MARKDOWN,
                DingerRequest.request("**企业微信机器人消息发送中间件**已启动！\n> 启动时间：" +
                        java.time.LocalDateTime.now(), "系统启动通知")
        );
    }
}
